package com.yz.lzq.liwushuo.model;

import android.util.Log;

import com.yz.lzq.liwushuo.bean.CategoryBean;
import com.yz.lzq.liwushuo.interfaces.CategorInterface;
import com.yz.lzq.liwushuo.util.UrlConfig;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by AdminJia on 2016/11/30.
 */

public class CategoryGongLBiz implements ICategoryGongLBiz {

    @Override
    public void getDataSuccess(final OnCategoryGongListener listener) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(UrlConfig.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create()).build();
        CategorInterface.CategoryGonglInterface categoryGonglInterface = retrofit.create(CategorInterface.CategoryGonglInterface
                .class);
        Call<CategoryBean.CategoryGongLBean> call = categoryGonglInterface.getGongLData();
        call.enqueue(new Callback<CategoryBean.CategoryGongLBean>() {
            @Override
            public void onResponse(Call<CategoryBean.CategoryGongLBean> call, Response<CategoryBean.CategoryGongLBean>
                    response) {

                CategoryBean.CategoryGongLBean body = response.body();
                CategoryBean.CategoryGongLBean.DataBean data = body.getData();
                List<CategoryBean.CategoryGongLBean.DataBean.ChannelGroupsBean> list_gongL = data
                        .getChannel_groups();
                Log.i("TAG", "---------------modle++++onResponse: " + list_gongL.size());
                listener.getDataSuccess(list_gongL);
            }

            @Override
            public void onFailure(Call<CategoryBean.CategoryGongLBean> call, Throwable t) {
                listener.getDataFailed(t);
            }
        });

    }

    @Override
    public void getHeaderDataSuccess(final OnCategoryGongHeaderListener listener) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(UrlConfig.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create()).build();
        CategorInterface.CategoryGonglInterface categoryGonglInterface = retrofit.create(CategorInterface.CategoryGonglInterface
                .class);
        Call<CategoryBean.CategoryGongLHeaderBean> call = categoryGonglInterface.getHeaderData();
        call.enqueue(new Callback<CategoryBean.CategoryGongLHeaderBean>() {
            @Override
            public void onResponse(Call<CategoryBean.CategoryGongLHeaderBean> call,
                                   Response<CategoryBean.CategoryGongLHeaderBean> response) {
                List<CategoryBean.CategoryGongLHeaderBean.DataBean.ColumnsBean> columns = response.body()
                        .getData().getColumns();
                listener.getHeaderDataSuccess(columns);

            }

            @Override
            public void onFailure(Call<CategoryBean.CategoryGongLHeaderBean> call, Throwable t) {

            }
        });
//        call.enqueue(new Callback<CategoryGongLBean>() {
//            @Override
//            public void onResponse(Call<CategoryGongLBean> call, Response<CategoryGongLBean>
//                    response) {
//
//                CategoryGongLBean body = response.body();
//                CategoryGongLBean.DataBean data = body.getData();
//                List<CategoryGongLBean.DataBean.ChannelGroupsBean> list_gongL = data
//                        .getChannel_groups();
//                listener.getDataSuccess(list_gongL);
//            }
//
//            @Override
//            public void onFailure(Call<CategoryGongLBean> call, Throwable t) {
//                listener.getDataFailed(t);
//            }
//        });
    }

    @Override
    public void getDataFailed() {

    }
}
